package com.lyf.alg.practice.newcoder.summary.hash;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @AUTHOR LYF
 * @DATE 2022/6/1
 * @VERSION 1.0
 * @DESC
 * 计数+排序
 */
public class StrCountSort {
    void test1(){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        Map<Character,Integer> map = new HashMap<>();
        //1.统计字符串
        for(int i=0;i<str.length();i++){
            Character ch = str.charAt(i);
            Integer val = map.get(ch);
            // 有对应的API？？
            if(val!=null){
                map.put(ch,val+1);
            }else{
                map.put(ch,1);
            }
//            map.computeIfAbsent(ch,k->1);
            //map.computeIfAbsent(ch);
//            map.computeIfPresent();

        }
        //2.标记最小的下标
        Character minCh=null;
        Integer minVal = 21;//最大，长度最大20
        for(Map.Entry<Character,Integer> entry:map.entrySet()){
            Character ch = entry.getKey();
            Integer val = entry.getValue();
            if(val<minVal){
                minCh=ch;
                minVal=val;
            }
        }
        String rs = "";
        //3.输出拼接
        for(int i=0;i<str.length();i++){
            if(map.get(str.charAt(i))!=minVal){
                rs = rs+str.charAt(i);
            }
        }
        System.out.println(rs);
    }






}
